package com.example.icedcap.topeka_fake.model.quiz;

import android.os.Parcel;

/**
 * Author: doushuqi
 * Date: 15/7/15
 * Time: 上午11:23
 * Email: shuqi.dou@singuloid.com
 */
public final class PickerQuiz extends Quiz<Integer> {

    private final int mMin, mMax, mStep;

    public PickerQuiz(String question, Integer answer, boolean solved, int min, int max, int step) {
        super(question, answer, solved);
        mMin = min;
        mMax = max;
        mStep = step;
    }

    protected PickerQuiz(Parcel in) {
        super(in);
        setAnswer(in.readInt());
        mMin = in.readInt();
        mMax = in.readInt();
        mStep = in.readInt();
    }

    public int getMin() {
        return mMin;
    }

    public int getMax() {
        return mMax;
    }

    public int getStep() {
        return mStep;
    }

    @Override
    public QuizType getQuizType() {
        return QuizType.PICKER;
    }

    @Override
    public String getStringAnswer() {
        return getAnswer().toString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeInt(getAnswer());
        dest.writeInt(mMin);
        dest.writeInt(mMax);
        dest.writeInt(mStep);
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = result * 31 + mMin;
        result = result * 31 + mMax;
        result = result * 31 + mStep;
        return result;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof PickerQuiz)) {
            return false;
        }
        PickerQuiz picker = (PickerQuiz) o;
        if (picker.mMin != mMin) {
            return false;
        }
        if (picker.mMax != mMax) {
            return false;
        }
        if (picker.mStep != mStep) {
            return false;
        }
        return true;
    }
}
